//
//  ViewController.m
//  UI05_delegate设计模式实现view点击事件回调
//
//  Created by Scott on 16/5/9.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "ViewController.h"
#import "CustomView.h"
#import "TouchView.h"

@interface ViewController () <CustomViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self createCustomView];
    [self createTouchView];
    
}


- (void)createCustomView {
    
    CustomView *viewOfRed = [[CustomView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)];
    [self.view addSubview:viewOfRed];
    [viewOfRed release];
    
    
    viewOfRed.backgroundColor = [UIColor redColor];
    
    // 指定delegate
    viewOfRed.delegate = self;
    
}

#pragma mark - CustomView delegate 
- (void)customViewShouldClick:(CustomView *)view {
    
    NSLog(@"%s", __func__);
    
}

- (void)customViewDidClick:(CustomView *)view {
    
    NSLog(@"%s", __FUNCTION__);
    self.view.backgroundColor = [UIColor greenColor];
}


- (void)createTouchView {
    
    TouchView *viewOfBlue = [[TouchView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    [self.view addSubview:viewOfBlue];
    [viewOfBlue release];
    
    viewOfBlue.backgroundColor = [UIColor blueColor];
    
    [viewOfBlue addTarget:self action:@selector(handleTouchView:)];
    
}

- (void)handleTouchView:(TouchView *)view {

    NSLog(@"%@", view.backgroundColor);
    
}




@end
